/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import logica.ManejadorRestaurante;
import logica.Restaurante;

/**
 *
 * @author Cajas
 */
public class BddlRestaurante implements Serializable {

    int id;
    String descripcion;
    List<Restaurante> lista;
    ManejadorRestaurante mr;

    /**
     * Creates a new instance of BddlRestaurante
     */
    public BddlRestaurante() {

    }

    public List<String> completeText(String query) {
        List<String> results = new ArrayList<String>();
        if (query != null) {
            List<Restaurante> ls = mr.getRestaurantes(query);
            for (Restaurante r : ls) {
                // if(cmp1.contentEquals(cmp2))
                results.add(r.getNombre());
            }
        }
        return results;
    }

    public void changeEvent() {
        try {
            Restaurante found = mr.getRestaurante(descripcion);
            FacesContext contex = FacesContext.getCurrentInstance();
            contex.getExternalContext().redirect("/Shuckapp/faces/menu.xhtml?marker=" + found.getCodigo());
        } catch (Exception e) {
            System.err.println("Me voy al carajo, no funciona esta redireccion");
        }
    }

    @PostConstruct
    public void init() {
        mr = new ManejadorRestaurante();
        lista = mr.getAllRestaurante();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public List<Restaurante> getLista() {
        return lista;
    }

    public void setLista(List<Restaurante> lista) {
        this.lista = lista;
    }

}
